-- LG Plneni fake atributu QI2 pro cizi uzly (spoustet)
<g>
update a102u0 set a40196485u10 = 0, ts0 = getdate(), useric = 1105, useru = 0 where (ic = 4679488 and u = 10016) or (ic = 1487656 and u = 10016) or (ic = 801794 and u = 10016) or (ic = 257788 and u = 10016) or (ic = 257790 and u = 10016) or (ic = 375978 and u = 10152)
</g>

-- PeM - nasypání hodnoty "Převádí" na položky ze strany B převáděcí vazby (NESPUSTIT)
<g>
update Mnoz set Mnoz.a42126786u10 = Prev.a209218u9, ts0 = getdate(), useric = 1105, useru = 0 from a29558u10 Mnoz
inner join a29555u10 as Pol on (Pol.ic = Mnoz.ic_a) and (Pol.u = Mnoz.u_a)
inner join a42107567u10 as Prev on (Prev.ic_b = Pol.ic) and (Prev.u_b = Pol.u)
where Prev.a209218u9 is not null
</g>

<g>
update Mnoz set Mnoz.a42126793u10 = Prev.a209220u9, ts0 = getdate(), useric = 1105, useru = 0 from a795402u10 Mnoz
inner join a29555u10 as Pol on (Pol.ic = Mnoz.ic_a) and (Pol.u = Mnoz.u_a)
inner join a42107567u10 as Prev on (Prev.ic_b = Pol.ic) and (Prev.u_b = Pol.u)
where Prev.a209220u9 is not null
</g>

-- LuP - výmaz převedení pož. na přeskl. z podřízené (NESPUSTIT)
<g>
select PREV.ic as IC, PREV.u as U
into #tmptable
from a209217u9 as PREV
join a33369u10 as POL on (POL.ic = PREV.ic_b and POL.u = PREV.u_b)
join a80961u10 as PP on (PP.ic_b = POL.ic and PP.u_b = POL.u)
join a4132u10 as DOKL on (DOKL.ic = PP.ic_a and DOKL.u = PP.u_a)
join a14954u10 as TD on (TD.ic_a = DOKL.ic and TD.u_a = DOKL.u)
join a14952u10 as TYP on (TYP.ic = TD.ic_b and TYP.u = TD.u_b)
where TYP.a1400817u10 is not null and TYP.a1400817u10 = 1 and TYP.a8073446u10 is not null and TYP.a8073446u10 = 2

update PREV set a42124011u10 = 1
from a42107567u10 as PREV
join #tmptable as TMP on (TMP.IC = PREV.ic and TMP.U = PREV.u)

delete PREV 
from a209217u9 as PREV
join #tmptable as TMP on (TMP.IC = PREV.ic and TMP.U = PREV.u)

drop table #tmptable
</g>


-- LuP: naplneni prepinace "Polozkove oceneno" ve tride "Polozky prijatych plneni" (NESPOUSTET)
<g>
select ic_b as IC, u_b as U
into #tmptable
from a10811985u10 PO
join a189270u10 as PPP on (PPP.ic = PO.ic_b and PPP.u = PO.u_b)
group by ic_b, u_b

update PPP
set a42281233u10 = 1
from a189270u10 as PPP
join #tmptable as TMP on (TMP.IC = PPP.ic and TMP.U = PPP.u)
where PPP.a42281233u10 is null
drop table #tmptable
</g>

-- MiK Konverze logovani posledniho sputeni (NESPOUSTET)
<g>
update a set a42404449u10 = 7, a42404451u10 = 0
from a15777u10 as a
join a15830u10 as b on b.ic = a.ic and b.u = a.u
where a20792357u10 = 1
</g>

-- OK Zruseni podrizenosti datovych rezu exportu a importu Plantune pod DT "Datové řezy programové funkce" (110,0) (SPOUSTET)
<g>
delete a from a110u0 as a join a12522031u10 as b on a.ic = b.ic and a.u = b.u
</g>


-- DINGO (NESPOUŠTĚT)

-- WMS: presun udaju zjisteneho stavu skladove pozice
<g>
update dst set useric = 1105, useru = 0, ts0 = getdate(), a530060u11011 = a479427u11011, a530063u11011 = a479425u11011
from
  a479422u11011 src
  inner join a188438u11011 dst on src.ic_a = dst.ic and src.u_a = dst.u and a530060u11011 is null and a530063u11011 is null and (a479427u11011 is not null or a479425u11011 is not null)
</g>

-- WMS: vypocet udaje "Pripraveno"
<g>
select Item.ic ic, Item.u u, sum(prepareItem.a139405u11011) PrepareQuantity
into #dingo_sumItems
from
  a139392u11011 Item
  left outer join a179056u11011 ItemLink on ItemLink.ic_b = Item.ic and ItemLink.u_b = Item.u
  left outer join a139392u11011 prepareItem on ItemLink.ic_a = prepareItem.ic and ItemLink.u_a = prepareItem.u
group by
  Item.ic, Item.u, Item.a530121u11011
having
  Item.a530121u11011 is null and sum(prepareItem.a139405u11011) is not null or (Item.a530121u11011 <> sum(prepareItem.a139405u11011))

update Item set useric = 1105, useru = 0, ts0 = getdate(), a530121u11011 = PrepareQuantity
from
  #dingo_sumItems
  inner join a139392u11011 Item on #dingo_sumItems.ic = Item.ic and #dingo_sumItems.u = Item.u

drop table #dingo_sumItems
</g>

-- WMS: Zdrojova davka pro terminal -> Zdrojove davky pro terminal
<g>
	<p>
	insert into a530154u11011 (u, ic, ts0, useric, useru, remotekey, langstate, u_a, ic_a, u_b, ic_b)
	select src.u, src.ic, getdate(), 1105, 0, src.remotekey, src.langstate, src.u_a, src.ic_a, src.u_b, src.ic_b
	</p>
	<a>
	insert into a530154u11011 (u, ic, ts0, useric, useru, remotekey, langstate, u_a, ic_a, u_b, ic_b, sstate, sstate_a, sstate_b)
	select src.u, src.ic, getdate(), 1105, 0, src.remotekey, src.langstate, src.u_a, src.ic_a, src.u_b, src.ic_b, 0, 0, 0
	</a>
	from
	  a179057u11011 src
	  left outer join a530154u11011 dst on src.ic = dst.ic and src.u = dst.u
	where
	  dst.ic is null
</g>

-- WMS: "Davky pro terminal" nastaveni priznaku "Zdrojove davky"
<g>
	-- davky se zdrojovou davkou
	select ic_a ic, u_a u, count(*) countBatch
	into #dingoTmp
	from a530154u11011
	group by ic_a, u_a
	
	-- nastaveni priznaku
	update batch set useric = 1105, useru = 0, ts0 = getdate(), a530161u11011 = countBatch
	from
	  a14439u11011 batch
	  left outer join #dingoTmp on batch.ic = #dingoTmp.ic and batch.u = #dingoTmp.u
	where
	  (#dingoTmp.ic is not null and (a530161u11011 is null or a530161u11011 <> countBatch)) or
	  (#dingoTmp.ic is null and a530161u11011 is not null)
	
	-- odstraneni pomocne tabulky
	drop table #dingoTmp
</g>

-- Doprava: Objekty casti zasilky -> odstraneni z rozpadu statku
<g>
	delete src
	from
	  a813089u10212 dst
	  inner join a3702790u10 src on dst.ic = src.ic_b and dst.u = src.u_b
	
	delete src
	from
	  a813089u10212 dst
	  inner join a3138000u10 src on src.ic = dst.ic and src.u = dst.u
</g>

-- DINGO END




